import os
import sys
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By 
from selenium.webdriver.firefox.service import Service as FirefoxService
from selenium.webdriver.common.action_chains import ActionChains
class LikeShopTest():
    def __init__(self) -> None:

        driver_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(sys.executable)))),
                               'geckodriver.exe')
        service = FirefoxService(executable_path=driver_path)
        options = webdriver.FirefoxOptions()
        self.browser = webdriver.Firefox(service=service, options=options)
    def test_1(self):
        self.browser.get('http://likeshop.abc/admin/account/login.html')
        sleep(2)
        self.browser.find_element(By.Name,'account').send_keys('dxg')
        self.browser.find_element(By.Name,'password').send_keys('13571357')
        self.browser.find_element(By.Name,'code').send_keys('111111')
        self.browser.find_element(By.ID,'login').click()
        sleep(3)
        self.browser.find_element(By.XPATH,'//*[@id="view"]/li[1]/a').click()
        sleep(2)
        iframe1 =self .browser.find_element(By.XPATH,'//*[@id="LAY_app_body"]/div[2]/iframe')
        self.browser.switch_to.frame(iframe1)
        self.browser.find_element(By.XPATH,'//*[@id="keyword"]').send_keys('文具')
        self.browser.find_element(By.XPATH,'/html/body/div/div/div[2]/div/div/div[1]/div/div[5]/button[1]').click()
        tr_list = self.browser.find_element(By.XPATH,'/html/body/div/div/div[2]/div/div/div[2]/div[2]/div[1]/div[2]/div]')
        tr_count =len(tr_list)
        
        if tr_count ==0:
            print('没有数据')
        is_not_bug = True
        for i in tr_list:
            shop_name =i.find_element(By.XPATH,'./td[2]/div').text
            if'文具' not in shop_name:
                is_not_bug = False
        if is_not_bug:
            print('商品列表查询没有问题')
        else:
            print('商品列表有问题')
        sleep()
        if __name__ =='__main__':
            likeShopTest = LikeShopTest()
            likeShopTest.tset_1()